<?php

function libxml_display_error($error) 
{ 
  $return = "<br/>\n"; 
  
  switch ($error->level) { 
    case LIBXML_ERR_WARNING: 
      $return .= "<b>Warning $error->code</b>: "; 
      break; 
    case LIBXML_ERR_ERROR: 
      $return .= "<b>Error $error->code</b>: "; 
      break; 
    case LIBXML_ERR_FATAL: 
      $return .= "<b>Fatal Error $error->code</b>: "; 
      break; 
  }
    
  $return .= trim($error->message); 
  
  if ($error->file) { 
    $return .= " in <b>$error->file</b>"; 
  }
  
  $return .= " on line <b>$error->line</b>\n"; 

  return $return; 
} /////////// end function libxml_display_error() //////////

function libxml_display_errors() { 
  
  $errors = libxml_get_errors(); 
  
  foreach ($errors as $error) { 
    print libxml_display_error($error); 
  } 
  libxml_clear_errors(); 
} 

//////////////////////////////////////////////
////// Script Execution Start ////////////////

//$xml_file_to_validate = './lures.xml';
//$schema_file          = 'lures.xsd';
$xml_file_to_validate = 'jobs.xml';
$schema_file          = 'XML/jobsSchema.xsd';

if(isset ($_GET['file'])) {
  $xml_file_to_validate = $_GET['file'];
}
if(isset ($_GET['schema'])) {
  $schema_file = $_GET['schema'];
}

// Enable user error handling 
libxml_use_internal_errors(true); 




$xml = new DOMDocument(); 
$xml->load($xml_file_to_validate); 

print '<h2>PHP XML Data Validator</h2>';

print "<p>For XML file <strong>$xml_file_to_validate</strong> and Schema <strong>$schema_file</strong>:<p/>"; 


if (!$xml->schemaValidate($schema_file)) { 
  print '<br/><b>Errors Found!</b><br/>'; 
  libxml_display_errors(); 
} 
else { 
  echo "<p>File <strong style='color:blue;'>validated</strong> <p/>"; 
} 

list($usec, $sec) = explode(" ", microtime());

$usec_converted = (int)($usec * 100000);

print "<p>Current time via microtime: $sec$usec_converted</p>";

// Obtain date
$dateArray = getdate();
$month = $dateArray['mon'];
$day   = $dateArray['mday'];
// get month into 2-digit form
if($month < 10) $month = "0" . $month;
// get day into 2-digit form
if($day  < 10) $day = "0" . $day;
$dateStr =   $dateArray['year'] . "-". $month . "-". $day; // YYYY-MM-DD

print "<p>Current date: $dateStr</p>";

?>


